'
Functions can be used to replace multiple code statements. This occurs in the TicTacToe game program within the tutorial \ufeffFinishing the TicTacToe Program; see the printBoard function created there as an example.
What if we wanted to replace the following lines in the TicTacToe game:
\ufeff
while col \ufeffor col :
\ufeffcol \ufeffintinputplayerTurn \ufeffplayer, select a column :
\ufeffif col \ufeffor col :
\ufeff printThe column must be between \ufeffand
with a function called turn. For the call to this function, we could use:
\ufeff
col \ufeffturncolumn \ufeffplayerTurn \ufeff
\ufeff
where we input into the function that we want to select a column column \ufeffand which player is making this selection playerTurn
Which code segment properly implements this function?
A
def turncolrow, player:
\ufeffgoodselection \ufeffFalse
\ufeffwhile goodselection \ufeffFalse:
\ufeff colrowpicked \ufeffintinputplayerTurn \ufeffplayer, select a : formatcolrow
\ufeff if colrowpicked \ufeffor colrowpicked :
\ufeff printThe \ufeffmust be between \ufeffand formatcolrow
\ufeff else:
\ufeff goodselection \ufeffTrue
\ufeff return colrow
B
def turncolrow, player:
\ufeffgoodselection \ufeffTrue
\ufeffwhile goodselection \ufeffFalse:
\ufeff colrowpicked \ufeffintinputplayerTurn \ufeffplayer, select a : formatcolrow
\ufeff if colrowpicked \ufeffor colrowpicked :
\ufeff printThe \ufeffmust be between \ufeffand formatcolrow
\ufeff else:
\ufeff goodselection \ufeffTrue
\ufeff return colrowpicked
C
def turncolrow, player:
\ufeffgoodselection \ufeffTrue
\ufeffwhile goodselection \ufeffFalse:
\ufeff colrowpicked \ufeffintinputplayerTurn \ufeffplayer, select a : formatcolrow
\ufeff if colrowpicked \ufeffor colrowpicked :
\ufeff printThe \ufeffmust be between \ufeffand formatcolrow
\ufeff else:
\ufeff goodselection \ufeffTrue
\ufeff return colrow
D
def turncolrow, player:
\ufeffgoodselection \ufeffFalse
\ufeffwhile goodselection \ufeffFalse:
\ufeff colrowpicked \ufeffintinputplayerTurn \ufeffplayer, select a : formatcolrow
\ufeff if colrowpicked \ufeffor colrowpicked :
\ufeff printThe \ufeffmust be between \ufeffand formatcolrow
\ufeff else:
\ufeff goodselection \ufeffTrue
\ufeff return colrowpicked
'